<script setup lang="ts">
import { localCache } from '@/utils/cache'
import panelAccount from './panel-account.vue'
import panelPhone from './pannel-phone.vue'
import { ref, watch } from 'vue'
const isRememberPwd = ref<boolean>(localCache.getCache('isRememberPwd') ?? false)
watch(isRememberPwd, (newValue) => {
  localCache.setCache('isRememberPwd', newValue)
})

const activeName = ref('account')
const accountRef = ref<InstanceType<typeof panelAccount>>()

function loginAciton() {
  if (activeName.value === 'account') {
    accountRef.value?.loginAccount(isRememberPwd.value)
  } else if (activeName.value === 'phone') {
    console.log('phone')
  }
}
</script>

<template>
  <div class="login-panel">
    <h2 class="title">后台管理系统</h2>
    <div class="tabs">
      <el-tabs type="border-card" stretch v-model="activeName">
        <el-tab-pane name="account">
          <template #label>
            <span class="icon">
              <el-icon>
                <UserFilled />
              </el-icon>
              <span class="text">账号登录</span>
            </span>
          </template>
          <panelAccount ref="accountRef" />
        </el-tab-pane>
        <el-tab-pane name="phone">
          <template #label>
            <span class="icon">
              <el-icon>
                <Iphone />
              </el-icon>
              <span class="text">手机登录</span>
            </span>
          </template>
          <panelPhone />
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="controls">
      <el-checkbox v-model="isRememberPwd" label="记住密码" />
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" size="large" class="login-btn" @click="loginAciton">立即登录</el-button>
  </div>
</template>
<style lang="less" scoped>
.login-panel {
  width: 330px;
  margin-bottom: 150px;

  .title {
    text-align: center;
    margin-bottom: 15px;
  }

  .icon {
    display: flex;
    align-items: center;
    justify-content: center;

    .text {
      margin-left: 5px;
    }
  }

  .controls {
    margin-top: 12px;
    display: flex;

    justify-content: space-between;
  }

  .login-btn {
    margin-top: 10px;
    width: 100%;

    --el-button-size: 50px;
  }
}
</style>
